<%--
  Created by IntelliJ IDEA.
  User: 31052
  Date: 2022/4/6
  Time: 18:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    String path =request.getContextPath();
%>
<script src="../js/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
    function login() {
        var name = $("#username").val();
        var pass = $("#password").val();


        alert(name)
        alert(pass)
        $.ajax({
            type:"post",
            url:"Hello",
            data :{
                "username":name,
                "password":pass
            },
            dataType:"text",

            success:function (data) {
                alert(data)

                if (data==1){
                    var path=document.getElementById("path").value;
                    window.location.href=path+"/index2.jsp"
                }

            },
            error:function () {

                alert("出异常了")
            }

        })

    }

</script>








<form class="login" action="#" method="post">
    标号：<input type="text" id="username" value="" />
    标题：<input type="text" id="password" value="" />
    <input type="hidden" id="path" value="<%=path%> "style="margin-left: 60px">
</form>
<button onclick="login()">添加</button>

</body>
</html>
